var xmlHttpRequest;
function createXMLHttpRequest()
{
    if (window.XMLHttpRequest) //非IE浏览器
    {
        xmlHttpRequest = new XMLHttpRequest();
    }
    else if (window.ActiveObject)//IE6以上版本的IE浏览器
    {
        xmlHttpRequest = new ActiveObject("Msxml2.XMLHTTP");
    }
    else //IE6及以下版本IE浏览器
    {
        xmlHttpRequest = new ActiveObject("Microsoft.XMLHTTP");
    }
}

function showInform(itemId) {
    console.log(itemId);
    sendRequest("itemShowJsServlet?itemId=" + itemId);
    //sendRequest("categoryShowJsServlet");
}

function sendRequest(url) {
    createXMLHttpRequest();
    xmlHttpRequest.open("GET", url, true);
    xmlHttpRequest.onreadystatechange = processResponse;
    xmlHttpRequest.send(null);
}



function processResponse()
{
    if (xmlHttpRequest.readyState == 4)
    {
        if (xmlHttpRequest.status == 200)
        {
            var resp = xmlHttpRequest.responseText;
            //显示悬浮层
            var inform = document.getElementById("inform");
            inform.innerText = resp;
            inform.style.display = "block";

        }
    }
}


document.onmousemove=function(ev)
{
    var oEvent=ev||event;
    var oDiv=document.getElementById('inform');
    var scrollTop=document.documentElement.scrollTop||document.body.scrollTop;
    var scrollLeft=document.documentElement.scrollLeft||document.body.scrollLeft;
    oDiv.style.left=oEvent.clientX+scrollLeft+'px';
    oDiv.style.top=oEvent.clientY+scrollTop+'px';
}


/*
document.onmousemove=function(even)
{
    var oDiv=document.getElementById('inform');
//            document.body  Chrome专用
    var scrollTop=document.documentElement.scrollTop||document.body.scrollTop;
    var scrollLeft=document.documentElement.scrollLeft||document.body.scrollLeft;

    var oEvent=even||event;
    oDiv.style.top = scrollTop+oEvent.clientY+"px";
    oDiv.style.left=scrollLeft+oEvent.clientX+"px";
}*/



//隐藏悬浮层
function hiddenInform()
{
    var informDiv = document.getElementById('inform');
    var x=event.clientX;
    var y=event.clientY;
    var divx1 = informDiv.getBoundingClientRect().left;
    var divy1 = informDiv.getBoundingClientRect().top;
    var divx2 = divx1 + informDiv.clientWidth;
    var divy2 = divy1+ informDiv.clientHeight;
    if( x < divx1 || x > divx2 || y < divy1 || y > divy2)
    {
        document.getElementById('inform').style.display='none';
    }
}

function hiddenInform2(event)
{
    document.getElementById('inform').style.display='none';
}